package com.cqc.parallxlistview01;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.cqc.parallxlistview01.view.ParallaxListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


    private List<String> list = new ArrayList<>();
    private ImageView ivHeader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final ParallaxListView listView = findViewById(R.id.listView);
        for (int i = 0; i < 20; i++) {
            list.add("item" + i);
        }

        View headerView = LayoutInflater.from(MainActivity.this).inflate(R.layout.header, null);
        ivHeader = headerView.findViewById(R.id.iv_header);
        listView.addHeaderView(headerView);

        listView.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, list));

        ivHeader.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                listView.setHeaderImageView(ivHeader);
                ivHeader.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });

    }
}
